其他
1960-2018年世界各国GDP排名变化--Matlab动图实现
[data,name]=xlsread('C:\Users\Desktop\MATLAB世界GDP动态变化\data.xls','Data','A5:BK268');
for i=1:length(data)
countries(i,1)=string(char(name(i,1)));
end
for i=1:59
gdp=data(:,i);
[gdp0,I]=sort(gdp);
countries0=countries(I);
aa=numel(find(isnan(gdp)));
countries00=countries0((length(data)-aa-14):(length(data)-aa),1);
gdp00=gdp0((length(data)-aa-14):(length(data)-aa),1);
tt=barh(diag(gdp00'),'stack','g');
set(gca,'YTicklabel',countries00);
if ismember("中国",countries00)
a=find(countries00=="中国");
set(tt(a),'FaceColor','r');
end
year=[int2str(i+1959),'年'];
title(year);
pause(0.1)
frame=getframe(gcf);
imind=frame2im(frame);
[imind,cm] = rgb2ind(imind,256);
if i==1
imwrite(imind,cm,'C:\Users\Desktop\MATLAB世界GDP动态变化\GDP.gif','gif', 'Loopcount',inf,'DelayTime',0.4);
else
imwrite(imind,cm,'C:\Users\Desktop\MATLAB世界GDP动态变化\GDP.gif','gif','WriteMode','append','DelayTime',0.4);
end
end
2图